<?php

namespace app\admin\model\sum\video;

use app\admin\model\sum\Common;
use traits\model\SoftDelete;

class Episodes extends Common
{

    use SoftDelete;

    protected $deleteTime = 'deletetime';
    // 表名
    protected $name = 'sum_episodes';

    // 追加属性
    protected $append = [
        'status_text',
        'image_url',
        'total_likes',
        'total_favorites',
        'total_shares',
        'total_comments',
    ];

    public function getTotalLikesAttr($value, $data)
    {
        return $data['likes']+$data['fake_likes'];
    }
    public function getTotalFavoritesAttr($value, $data)
    {
        return $data['favorites']+$data['fake_favorites'];
    }
    public function getTotalSharesAttr($value, $data)
    {
        return $data['shares']+$data['fake_shares'];
    }
    public function getTotalCommentsAttr($value, $data)
    {
        $comment_count=Comment::where('episode_id',$data['id'])->where('pid',0)->count();
        return $comment_count;
    }
    public function getImageUrlAttr($value, $data)
    {
        $image_url = $data['image']?cdnurl($data['image'], true):'';
        return $image_url;
    }

}
